<template>
  <div class="app-container">
    <section>
      <div class="contentBox" v-loading="loading">
        <div class="infoWrap" v-if="details.user">
          <div class="left">
            <img :src="details.user.avatar" alt="" />
            <div>
              <div class="name">{{ details.user.username }}</div>
              <div v-if="details.user.vip">
                会员等级：{{ details.user.vip.title || "散客" }}
              </div>
              <div v-else>会员等级：散客</div>
            </div>
          </div>
          <div class="right">提交时间：{{ details.create_time }}</div>
        </div>
        <!-- 评分 -->
        <div class="gradeWrap" v-if="details.ordersProject">
          <template v-if="details.ordersProject.id">
            <img :src="details.ordersProject.project_images" alt="" />
            <div class="gradeBox">
              <div class="gradeT">
                <p>项目名称：{{ details.ordersProject.project_name }}</p>
                <div class="tagWrap">
                  <span>评价标签：</span>
                  <div class="tag">
                    <p
                      style="margin: 0 3px"
                      v-for="(ele, index) in typeList"
                      :key="index"
                    >
                      {{ ele.title }}
                    </p>
                  </div>
                </div>
                <p>评价内容：{{ details.content }}</p>
              </div>
              <div class="gradeB">
                <div class="left">
                  <p>
                    <span class="tit">项目评分：</span>
                    <el-rate disabled v-model="details.project_score"></el-rate>
                  </p>
                  <p>
                    <span class="tit">前台服务评分:</span>
                    <el-rate disabled v-model="details.project_score"></el-rate>
                  </p>
                  <p>
                    <span class="tit">环境评分：</span>
                    <el-rate disabled v-model="details.ambient"></el-rate>
                  </p>
                </div>
                <div class="right">
                  <p>
                    <span class="tit">服务技师：</span>
                    <span>{{details.ordersProject.staff.name}}({{details.ordersProject.staff.number}})</span>
                  </p>
                  <!-- <p>
                                     <span class="tit">技师技术评分：</span>
                                      <el-rate v-model="details.ambient"></el-rate>
                                 </p> -->
                  <p>
                    <span class="tit">技师服务评分：</span>
                    <el-rate disabled v-model="details.tech_service"></el-rate>
                  </p>
                </div>
              </div>
            </div>
          </template>
        </div>
        <!-- 评论图片 -->
        <div class="gradeImg" v-if="details.files">
          <p>评论图片</p>
          <div class="imgbox">
            <el-image
              v-for="(ele, index) in details.files"
              :key="index"
              :src="ele"
              alt=""
              :preview-src-list="details.files"
            ></el-image>
          </div>
        </div>
        <div class="content">
          <div class="replyInfo">
            <p v-if="details.admin">回复管理者：{{ details.admin.realname }}</p>
            <p v-else>回复管理者：{{ userInfo.realname }}</p>
            <p v-if="details.reply_time">
              回复时间：{{ details.reply_time | parseTime() }}
            </p>
            <p v-else>回复时间：{{ dete }}</p>
            <p>回复内容：</p>
          </div>
          <el-input
            v-if="type == 2"
            :readonly="type == 2 ? false : true"
            v-model="form.reply_content"
            type="textarea"
            :rows="6"
          ></el-input>
          <el-input
            v-else
            :readonly="type == 2 ? false : true"
            v-model="details.reply_content"
            type="textarea"
            :rows="6"
          ></el-input>
          <div style="margin-top: 40px" v-if="type == 2">
            <el-button type="primary" style="width: 100px" @click="save"
              >确定回复</el-button
            >
            <el-button style="width: 100px" @click="$router.go(-1)"
              >取消回复</el-button
            >
          </div>
          <div style="margin-top: 40px" v-else>
            <el-button style="width: 100px" @click="$router.go(-1)"
              >返回</el-button
            >
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
import VsUploading from "../../components/VsUploading";
export default {
  components: {
    VsUploading,
  },
  data() {
    var url = (rule, value, callback) => {
      // 图片验证
      if (!this.form.url) {
        //hasFmt设置为true/false
        callback(new Error("请上传图片!"));
      } else {
        callback();
      }
    };
    return {
      loading: false,
      value1: 4,
      form: {
        id: "",
        reply_content: "",
      },
      type: "",
      rules: {
        role_id: [{ required: true, message: "请选择角色", trigger: "blur" }],
      },
      roleList: [],
      details: {},
      dete: "",
      labelList: [],
      typeList: [],
    };
  },
  computed: {
    ...mapState("user", ["userInfo"]),
  },
  created() {
    console.log(this.userInfo, "888888888");
    if (this.$route.query.id) {
      // 获取当前时间
      let date = new Date();
      this.dete = this.utils.getNowDate(date);
      console.log(this.dete, "88888888888");
      this.form.id = this.$route.query.id;
      this.type = this.$route.query.type;
      this.getEvaluate();
    }
  },
  mounted() {},
  methods: {
    // 获取标签列表
    async getEvaluate() {
      let { code, data } = await this.$Http.getEvaluate({ is_all: 1 });
      if (code) {
        this.labelList = data;
        this.getDetails();
      }
    },
    // 获取详情
    async getDetails() {
      this.loading = true;
      let { code, data } = await this.$Http.projectGetComment({
        id: this.form.id,
      });
      if (data.files) {
        data.files = data.files.split(",");
      }
      this.loading = false;
      this.details = data;
      let evaluate_label_id = String(this.details.evaluate_label_id).split(",");
      let typeList = [];
      evaluate_label_id.forEach((item) => {
        this.labelList.forEach((list) => {
          if (item == list.id) {
            typeList.push(list);
          }
        });
        this.typeList = typeList;
      });
    },
    async save() {
      if (!this.form.reply_content) {
        this.$message.error("请输入回复内容");
        return;
      }
      let { code } = await this.$Http.projectReplyComment(this.form);
      if (code) {
        this.$message.success("回复成功");
        this.$router.go(-1);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  section {
    .contentBox {
      background: #fff;
      border-radius: 8px;
      padding: 0 24px 20px;
      min-width: 900px;
      min-height: calc(100vh - 165px);
      .infoWrap {
        padding-top: 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #333;
        font-size: 14px;
        .left {
          display: flex;
          align-items: center;
        }
        img {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          object-fit: cover;
          margin-right: 20px;
        }
        .name {
          margin-bottom: 6px;
        }
      }
      .gradeWrap {
        padding: 30px;
        width: 100%;
        box-sizing: border-box;
        background: #f1f1f1;
        margin: 32px 0;
        display: flex;
        p {
          margin: 0px;
        }
        .tagWrap {
          margin: 15px 0;
          display: flex;
          align-items: center;
          .tag {
            display: flex;
            p {
              margin: 0 15px;
              padding: 6px 10px;
              background: #999;
              border-radius: 2px;
              font-size: 14px;
            }
          }
        }
        > img {
          display: block;
          object-fit: cover;
          width: 100px;
          height: 100px;
          margin-right: 35px;
        }
        .gradeT {
          font-size: 16px;
          color: #383b40;
        }
        .gradeB {
          display: flex;
          margin-top: 15px;
          font-size: 16px;
          color: #383b40;
          .left,
          .right {
            p {
              display: flex;
              align-items: center;
              margin-bottom: 12px;
              .tit {
                display: block;
                width: 120px;
              }
            }
          }
          .left {
            margin-right: 100px;
          }
        }
      }
      .title {
        line-height: 70px;
        font-size: 18px;
        font-weight: 600;
        color: #383b40;
        .el-icon-close {
          cursor: pointer;
        }
      }
    }
    .content {
      min-width: 800px;
      height: 100%;
      .form {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
      }
    }
  }
}
.gradeImg {
  > p {
    font-size: 18px;
    color: #383b40;
  }
  .imgbox {
    display: flex;
    flex-wrap: wrap;
    .el-image {
      margin-right: 30px;
      display: block;
      width: 100px;
      height: 100px;
      margin-bottom: 30px;
    }
  }
}
::v-deep {
  .el-input {
    width: 250px;
  }
}
.imgbox {
  display: flex;
  flex-wrap: wrap;
  img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    margin-right: 20px;
  }
}
.replyBox {
  margin-left: 0;
  margin-bottom: 0;
  ::v-deep {
    .el-form-item__content {
      margin-left: 0 !important;
    }
  }
}
.replyInfo {
  background: #f1f1f1;
  padding: 0 10px;
  p {
    color: #999;
    font-size: 16px;
    margin: 0;
    line-height: 33px;
  }
}
.shopImg {
  width: 100px;
}
</style>